MRTG Start | Stop | Status | Restart

Publicado por Fernando Ribeiro 08/03/2005

[ Hits: 12.389 ]

Homepage: http://www.vivaolinux.com.br/~fernandofat

Download mrtg




Este script manipula o daemon do MRTG das seguintes maneiras:
Start | Stop | Status | Restart

Os caminhos dos arquivos do MRTG podem variar dependendo de como o MRTG foi compilado, neste caso é só alterar as variáveis no começo do script.

No meu Red Hat coloquei o script em /etc/rc.d/init.d e ficou muito bom, facilitando bastante.

  



Esconder código-fonte

#!/bin/bash

# Configuration
MRTG_BIN=/usr/local/mrtg-2/bin/mrtg
MRTG_CONF=/etc/mrtg.conf
MRTG_LOCK_FILE=/var/lock/subsys/mrtg
MRTG_PID_FILE=/var/run/mrtg.pid
MRTG_LOG_FILE=/var/log/mrtg/mrtg.log

getpid ()
{
   if [ -f $MRTG_PID_FILE ]; then
      MRTG_PID=`head -n 1 $MRTG_PID_FILE`
      return 0
   else
      echo "Error - PID file does not exist!!!"
      exit 1
   fi
}

startmrtg ()
{
   if [ -f $MRTG_PID_FILE ]; then
      echo "Can not start MRTG is already running!!!"
      statusmrtg
      return 1
   else
      echo "Starting MRTG:"
      env LANG=C $MRTG_BIN $MRTG_CONF  --lock-file $MRTG_LOCK_FILE \
                              --pid-file=$MRTG_PID_FILE \
                                                                 --logging $MRTG_LOG_FILE > /dev/null
      sleep 5
      if [ -f $MRTG_PID_FILE ]; then
         echo "MRTG started OK!!!"
         statusmrtg
         return 0
      else
         echo "MRTG did NOT start, check configuration!!!"
         statusmrtg
         return 1
      fi
   fi
}

stopmrtg ()
{

      if [ -f $MRTG_PID_FILE ]; then
         getpid
         echo "Stopping MRTG:"
         kill $MRTG_PID
         rm -f $MRTG_LOCK_FILE
         while [ -f $MRTG_PID_FILE ]
         do
            sleep 1
         done
         echo "MRTG stopped OK!!!"
         statusmrtg
         return 0
      else
         echo "MRTG was not running!!!"
         statusmrtg
         return 1
      fi
}

statusmrtg ()
{
      if [ -f $MRTG_PID_FILE ]; then
         getpid
         echo "Status MRTG: Running!"
         echo "Process ID: $MRTG_PID"
         return 0
      else
         echo "Status MRTG: Not running!"
         return 1
      fi
}

         
case "$1" in

   start)
      startmrtg
      ;;

   stop)
      stopmrtg
      ;;

   status)
      statusmrtg
      ;;

   restart)
      stopmrtg
      startmrtg
      ;;

   *)
      echo "Usage: mrtg {start|stop|restart|status}"
      exit 1
      ;;

esac

Scripts recomendados

Speedy Business - HowTo 2.0

"desmontar" partiçao fat

Acessar celular Motorola via USB

Configurar 3G

Desmontar e Ejetar CD/DVD


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts